import request from '@/config/axios'

// 学生成绩 VO
export interface ExamScoreVO {
  id: number // 主键ID
  examId: number // 考试ID
  studentId: number // 学生ID
  studentNo: string // 学号
  studentName: string // 学生姓名
  chineseScore: number // 语文成绩
  mathScore: number // 数学成绩
  englishScore: number // 英语成绩
  physicsScore: number // 物理成绩
  chemistryScore: number // 化学成绩
  biologyScore: number // 生物成绩
  politicsScore: number // 政治成绩
  historyScore: number // 历史成绩
  geographyScore: number // 地理成绩
  japaneseOriginalScore: number // 日语成绩
  spanishOriginalScore: number // 西班牙语成绩
  russianOriginalScore: number // 俄语成绩
  totalScore: number // 总分
  classRank: number // 班级排名
  gradeRank: number // 年级排名
}

// 学生成绩 API
export const ExamScoreApi = {
  // 查询学生成绩分页
  getExamScorePage: async (params: any) => {
    return await request.get({ url: `/system/exam-score/page`, params })
  },

  // 查询学生成绩详情
  getExamScore: async (id: number) => {
    return await request.get({ url: `/system/exam-score/get?id=` + id })
  },

  // 新增学生成绩
  createExamScore: async (data: ExamScoreVO) => {
    return await request.post({ url: `/system/exam-score/create`, data })
  },

  // 修改学生成绩
  updateExamScore: async (data: ExamScoreVO) => {
    return await request.put({ url: `/system/exam-score/update`, data })
  },

  // 删除学生成绩
  deleteExamScore: async (id: number) => {
    return await request.delete({ url: `/system/exam-score/delete?id=` + id })
  },

  // 导出学生成绩 Excel
  exportExamScore: async (params) => {
    return await request.download({ url: `/system/exam-score/export-excel`, params })
  },

  // 导入学生成绩
  importExamScore: async (data) => {
    return await request.upload({ url: `/system/exam-score/import`, data })
  },

  // 导入学生成绩（支持自定义超时时间）
  importExamScoreWithTimeout: async (data, timeout = 300000) => {
    return await request.upload({ 
      url: `/system/exam-score/import`, 
      data,
      timeout
    })
  },

  // 下载学生成绩导入模板
  importTemplate: async () => {
    return await request.download({ url: `/system/exam-score/get-import-template` })
  },

  // 导出学生账号 Excel
  exportStudentAccounts: async (params) => {
    return await request.download({ url: `/system/exam-class-student/export-student-accounts`, params })
  },

  // 导出老师账号 Excel
  exportTeacherAccounts: async (params) => {
    return await request.download({ url: `/system/exam-class/export-teacher-accounts`, params })
  },

  // 导出等效分 Excel
  exportEquivalentScore: async (params) => {
    return await request.download({ url: `/system/exam-score/export-equivalent-score`, params })
  },

  // 清除某次导入的所有成绩数据
  clearImportedScores: async (examId: number) => {
    return await request.delete({ url: `/system/exam-score/clear-import?examId=` + examId })
  },
}
